
package com.noah.project.dao

import com.noah.project.model.Mark
import com.noah.project.model.Note
import com.noah.project.model.ReplyNote
import org.apache.ibatis.annotations.*
import org.springframework.stereotype.Repository

@Repository
interface MarkDao {
    @Insert("INSERT INTO mark(mid, nid, mTime) VALUES(#{mid}, #{nid}, #{mTime})")
    fun insert(mark: Mark): Long

    @Delete("DELETE FROM mark WHERE mid = #{mid} AND nid = #{nid}")
    fun delete(mark: Mark): Long

    @Select("SELECT * FROM mark WHERE mid = #{mid} AND nid = #{nid}")
    fun findMark(mid: Long?, nid: Long?): Mark?

    @Select("SELECT * FROM mark LEFT JOIN note ON mark.nid = note.nid WHERE mark.mid = #{mid} AND mark.mTime < #{time} order by mark.mTime desc LIMIT 10")
    @Results(Result(column = "uid", property = "user", one = One(select = "com.noah.project.dao.UserDao.findReplyById")),
            Result(column = "bid", property = "book", one = One(select = "com.noah.project.dao.BookDao.findReplyById")))
    fun findMarkNotes(mid: Long?, time: Long?): List<ReplyNote>//重名的时候,把下面的id改掉和上面的#{id}
}
